<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
/**
 * 仓库控制器
 */
class DepotController extends CommonController{
	/**
	 * 仓库列表
	 */
	public function index(){
		$pageNum=I('pageNum',1,intval);//第几页
		$numPerPage=I('numPerPage',10,intval);//每页显示条数

		//获取排序的字段及排序方式
		$orderField=$_POST['_order']?$_POST['_order']:'id';
		$orderDirection=$_POST['_sort']?$_POST['_sort']:'asc';
		//组合排序字符串
		$orders=($orderField.' '.$orderDirection);
		$db=M('depot');
		//获取总数据条数
		$count=$db->count();
		$this->assign('totalCount',$count);//数据的总条数
		$this->assign('numPerPage',$numPerPage);//每页显示多少条
		$this->assign('pageNumShown',6);//页标数字多少个
		$this->assign('currentPage',$pageNum);//当前是第几页
		$page= new \Think\Page($count,$numPerPage);
		$this->depot=$db->limit($numPerPage)->Page($pageNum)->order($orders)->where(array('del'=>'0'))->select();
		//权限菜单的显示与隐藏	
		$this->assign('depot_addId',110);//添加
		$this->assign('depot_editId',120);//编辑
		$this->assign('depot_delId',121);//删除
		$this->display();

	}
	public function lookup(){
		$pageNum=I('pageNum',1,intval);//第几页
		$numPerPage=I('numPerPage',10,intval);//每页显示条数
		//获取排序的字段及排序方式
		$orderField=$_POST['_order']?$_POST['_order']:'id';
		$orderDirection=$_POST['_sort']?$_POST['_sort']:'asc';
		//组合排序字符串
		$orders=($orderField.' '.$orderDirection);

		//检索条件
        if($_POST['search_where']){
            $this->search_where=$_POST['search_where'];
        }
        $where=$this->_search();
        //在where条件中增加未删除的判断条件
        $where['del']=array('eq','0');
        $depots=session('depots');
        $where['id']=array('in',$depots);
		$db=M('depot');
		//获取总数据条数
		$count=$db->where($where)->count();
		$this->assign('totalCount',$count);//数据的总条数
		$this->assign('numPerPage',$numPerPage);//每页显示多少条
		$this->assign('pageNumShown',6);//页标数字多少个
		$this->assign('currentPage',$pageNum);//当前是第几页
		$page= new \Think\Page($count,$numPerPage);
		$this->list=$db->limit($numPerPage)->Page($pageNum)->order($orders)->where($where)->select();
		$this->display();
	}
	public function lookupSuggest(){
		$where['del']=array('eq','0');
        $depots=session('depots');
        $where['id']=array('in',$depots);
        $db=M('depot');
        $depot=$db->where($where)->field(array('id','name'))->select();
        $arr="";
        $str .='[';
        foreach ($depot as $v) {
        	$str.='{"id":"';
        	$str.=$v['id'];
        	$str .='", "name":"';
        	$str .=$v['name'];
        	$str .='"},';
        }
        $str=rtrim($str,',');
        $str.=']';
        echo $str;
	}
	public function lookupAll(){
		$pageNum=I('pageNum',1,intval);//第几页
		$numPerPage=I('numPerPage',10,intval);//每页显示条数
		//获取排序的字段及排序方式
		$orderField=$_POST['_order']?$_POST['_order']:'id';
		$orderDirection=$_POST['_sort']?$_POST['_sort']:'asc';
		//组合排序字符串
		$orders=($orderField.' '.$orderDirection);

		//检索条件
        if($_POST['search_where']){
            $this->search_where=$_POST['search_where'];
        }
        $where=$this->_search();
        //在where条件中增加未删除的判断条件
        $where['del']=array('eq','0');
		$db=M('depot');
		//获取总数据条数
		$count=$db->where($where)->count();
		$this->assign('totalCount',$count);//数据的总条数
		$this->assign('numPerPage',$numPerPage);//每页显示多少条
		$this->assign('pageNumShown',6);//页标数字多少个
		$this->assign('currentPage',$pageNum);//当前是第几页
		$page= new \Think\Page($count,$numPerPage);
		$this->list=$db->limit($numPerPage)->Page($pageNum)->order($orders)->where($where)->select();
		$this->display('lookup');
	}
	public function lookupSuggestAll(){
		$where['del']=array('eq','0');
        $db=M('depot');
        $depot=$db->where($where)->field(array('id','name'))->select();
        $arr="";
        $str .='[';
        foreach ($depot as $v) {
        	$str.='{"id":"';
        	$str.=$v['id'];
        	$str .='", "name":"';
        	$str .=$v['name'];
        	$str .='"},';
        }
        $str=rtrim($str,',');
        $str.=']';
        echo $str;
	}


}